import nmap
host='192.168.1.105'

def synchronous_scanning():
    scanner=nmap.PortScanner()
    scanner.scan(hosts='192.168.1.105',arguments='sS',ports='1-5000')
    print(scanner.command_line())   # show the nmap commandline in terminal
    print(scanner.csv())
    print(scanner.all_hosts())
    print(scanner['192.168.1.105'].all_tcp())   
    print(scanner['192.168.1.105']['tcp'][22])  # different way show the 22 port of host's information
    print(scanner['192.168.1.105'].tcp(22)) 

def call_back(host,scan_data):
    print(host,scan_data)
    print('hello world!')
    
    
def asynchronous_scanning():
    scanner=nmap.PortScannerAsync()
    scanner.scan(hosts='192.167.1.105-110',arguments='sS',ports='1-5000',callback=call_back)
    while scanner.still_scanning():
        print("scanning is runing")
        scanner.wait(timeout=2)     #must set timeout;or the programming don't show anything ;exit immediately
asynchronous_scanning()

